package com.crm.CLdriving.common;

import java.io.Serializable;
import java.util.List;

import com.baomidou.mybatisplus.plugins.Page;
import com.crm.CLdriving.enu.ResponseEnum;
import com.crm.CLdriving.po.CostPO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel(value = "分页响应", description = "分页响应")
// @NoArgsConstructor
public class PageResponse<T>  implements Serializable {

	private static final long serialVersionUID = 5263929449909418122L;
	@ApiModelProperty(name = "data", value = "列表数据")
	private T data;

	@ApiModelProperty(name = "total", value = "总条数")
	private int total;
	@ApiModelProperty(name = "Pages", value = "总页数")
	private int pages;

	@ApiModelProperty(name = "pageNum", value = "当前页数")
	private int pageNum;
	@ApiModelProperty(name = "pageSize", value = "每页条数")
	private int pageSize;

	private String code;
	private String msg;

	public static <T> PageResponse<T> successOfPage(T t, Page page){
		PageResponse<T> PageResponse = new PageResponse<>();
		PageResponse.setData(t);
		PageResponse.setTotal(page.getTotal());//总条数
		PageResponse.setPages(page.getPages());//总页数
		PageResponse.setPageNum(page.getCurrent());//当前页数
		PageResponse.setPageSize(page.getSize());//每页条数
		return PageResponse;
	}


    public static<T> PageResponse<T> message(ResponseEnum zwsj) {
		PageResponse<T> PageResponse = new PageResponse<>();
		PageResponse.setCode(zwsj.getCode());
		PageResponse.setMsg(zwsj.getMsg());
		return PageResponse;
    }
}
